package com.thon.service.paper;

import com.thon.commons.persistence.Page;
import com.thon.dao.paper.RelationDao;
import com.thon.entity.paper.Relation;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Chen on 2016/2/23.
 */
@Service
@Transactional
public class RelationService {
    
    @Autowired
    private RelationDao relationDao;

    //get
    public Relation getRelation(int id){
        return relationDao.get(id);
    }

    //save
    public void saveRelation(Relation relation){
        relationDao.save(relation);
    }

    //delete
    public void delRelation(Relation relation){
        relationDao.delete(relation);
    }

    //list
    public Page<Relation> findRelations(Page<Relation> page, Relation Relation) {
        DetachedCriteria dc = relationDao.createDetachedCriteria();

        dc.addOrder(Order.desc("id"));

        return relationDao.find(page, dc);
    }
}
